function spp_exp_cache_features_voc(chunk, opts)

% -------------------- CONFIG --------------------
if ~exist('opts', 'var')
    opts.net_file        = fullfile(pwd, 'data','cnn_model','Zeiler_conv5','Zeiler_conv5');
    opts.net_def_file    = fullfile(pwd, 'data','cnn_model','Zeiler_conv5','Zeiler_spm_scale224_test_conv5.prototxt');
    opts.spp_params_def  = fullfile(pwd, 'data','cnn_model','Zeiler_conv5','spp_config');

    opts.flip                   = false;
    opts.feat_cache_copy_from   = 'Zeiler_conv5_back';
    opts.feat_cache             = 'Zeiler_conv5';
    opts.spm_im_size            = [480 576 688 874 1200];

    % change to point to your VOCdevkit install
    opts.devkit = './datasets/VOCdevkit2007';
else
    if isfield(opts, 'flip_finetune')
        opts.flip = opts.flip | opts.flip_finetune;
    end
end

imdb_train = imdb_from_voc(opts.devkit, 'train', '2007', opts.flip);
imdb_val   = imdb_from_voc(opts.devkit, 'val', '2007', opts.flip);
imdb_test  = imdb_from_voc(opts.devkit, 'test', '2007');
imdb_trainval = imdb_from_voc(opts.devkit, 'trainval', '2007', opts.flip);

% imdb_train_copy_from = struct();
% imdb_val_copy_from = struct();
% imdb_test_copy_from = struct();
% imdb_trainval_copy_from = struct();

imdb_train_copy_from = imdb_train;
imdb_val_copy_from = imdb_val;
imdb_test_copy_from = imdb_test;
imdb_trainval_copy_from = imdb_trainval;

switch chunk
  case 'trainval'
    spp_cache_convX_features(imdb_trainval, ...
        'imdb_copy_from', imdb_trainval_copy_from, ...
        'spm_im_size', opts.spm_im_size, ...
        'net_def_file', opts.net_def_file, ...
        'net_file', opts.net_file, ...
        'spp_params_def', opts.spp_params_def, ...
        'cache', opts.feat_cache, ...
        'cache_copy_from', opts.feat_cache_copy_from);
  case 'train'
    spp_cache_convX_features(imdb_train, ...
        'imdb_copy_from', imdb_train_copy_from, ...
        'spm_im_size', opts.spm_im_size, ...
        'net_def_file', opts.net_def_file, ...
        'net_file', opts.net_file, ...
        'spp_params_def', opts.spp_params_def, ...
        'cache', opts.feat_cache, ...
        'cache_copy_from', opts.feat_cache_copy_from);
    link_up_trainval(opts.feat_cache, imdb_train, imdb_trainval);
  case 'val'
    spp_cache_convX_features(imdb_val, ...
        'imdb_copy_from', imdb_val_copy_from, ...
        'spm_im_size', opts.spm_im_size, ...
        'net_def_file', opts.net_def_file, ...
        'net_file', opts.net_file, ...
        'spp_params_def', opts.spp_params_def, ...
        'cache', opts.feat_cache, ...
        'cache_copy_from', opts.feat_cache_copy_from);
    link_up_trainval(opts.feat_cache, imdb_val, imdb_trainval);
   case 'test'
    spp_cache_convX_features(imdb_test, ...
        'imdb_copy_from', imdb_test_copy_from, ...
        'spm_im_size', opts.spm_im_size, ...
        'net_def_file', opts.net_def_file, ...
        'net_file', opts.net_file, ...
        'spp_params_def', opts.spp_params_def, ...
        'cache', opts.feat_cache, ...
        'cache_copy_from', opts.feat_cache_copy_from);
  case 'test_1'
    end_at = ceil(length(imdb_test.image_ids)/2);
    spp_cache_convX_features(imdb_test, ...
        'imdb_copy_from', imdb_test_copy_from, ...
        'start', 1, 'end', end_at, ...
        'spm_im_size', opts.spm_im_size, ...
        'net_def_file', opts.net_def_file, ...
        'net_file', opts.net_file, ...
        'spp_params_def', opts.spp_params_def, ...
        'cache', opts.feat_cache, ...
        'cache_copy_from', opts.feat_cache_copy_from);
  case 'test_2'
    start_at = ceil(length(imdb_test.image_ids)/2)+1;
    spp_cache_convX_features(imdb_test, ...
        'imdb_copy_from', imdb_test_copy_from, ...
        'start', start_at, ...
        'spm_im_size', opts.spm_im_size, ...
        'net_def_file', opts.net_def_file, ...
        'net_file', opts.net_file, ...
        'spp_params_def', opts.spp_params_def, ...
        'cache', opts.feat_cache, ...
        'cache_copy_from', opts.feat_cache_copy_from);
end



% ------------------------------------------------------------------------
function link_up_trainval(cache, imdb_split, imdb_trainval)
% ------------------------------------------------------------------------
mkdir_if_missing(fullfile(pwd, 'feat_cache', cache, imdb_trainval.name));
copyfile(fullfile(pwd, 'feat_cache', cache, imdb_split.name, '*.mat'), ...
    fullfile(pwd, 'feat_cache', cache, imdb_trainval.name));
